cmake_minimum_required(VERSION 3.17)

project(CMakeBasic)

# 使用子项目来增加执行文件
add_subdirectory(Main)
add_subdirectory(CopyExe)

# 使用custom_target来执行外部程序
add_custom_target(MoveData
    COMMAND executable.bat
    WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
    COMMENT "Moveing data..."
)
# 设置Exe需要这个MoveData
add_dependencies(Exe MoveData)

# 使用custom_target来执行内部程序
add_custom_target(CopyExeRun
    COMMAND CopyExe
    WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
    COMMENT "执行内部程序..."
)
add_dependencies(Exe CopyExeRun)

# 使用custom_target来执行Python
add_custom_target(PythonExe
    COMMAND python.exe ./my_file.py
    WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
    COMMENT "执行Python程序..."
)
add_dependencies(Exe PythonExe)

# 更加跨平台的做法
find_package(Python3 COMPONENTS Interpreter)
    if(${Python3_Interpreter_FOUND})
    add_custom_target(Python3Exe
        COMMAND ${Python3_EXECUTABLE} ./my_file.py
        WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
        COMMENT "执行Python3程序..."
    )
    add_dependencies(Exe Python3Exe)
else()
    message(ERROR "Cannot find python.")
endif()
